package com.xyc.redis.controller;

import com.xyc.redis.cache.RedisHandler;
import com.xyc.redis.vo.JsonResultVO;
import com.xyc.redis.vo.ProductVO;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
public class ZanController {

    @Resource
    private RedisHandler redisHandler;

    @ResponseBody
    @RequestMapping("dianzan")
    public JsonResultVO returnZanRedis(Integer goodsId){
        JsonResultVO jsonResultVO = new JsonResultVO();
        String key = "pjname-zan-"+1+"-"+goodsId;
        try {
            redisHandler.setString(key,"1");//存到缓存中
            jsonResultVO.setCode(0);
            jsonResultVO.setMsg("success");
        } catch (Exception e) {
            e.printStackTrace();
            jsonResultVO.setCode(1);
            jsonResultVO.setMsg("fail");
        }
        return jsonResultVO;
    }
}
